package top.wyloop.fasthome.config;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;

/**
 * @author Wyatt6
 * @date 2025/5/15
 */
@Slf4j
@Configuration
public class CaffeineCacheConfig {
    public static final int captchaExpireSeconds = 180;    // 验证码过期时长：3分钟

    @Bean("captchaCache")
    public Cache<String, String> getCaptchaCache() {
        return Caffeine.newBuilder()
                .initialCapacity(100)   // 初始缓存池大小
                .maximumSize(1000)      // 缓存池最大缓存的条数
                .expireAfterWrite(Duration.ofSeconds(captchaExpireSeconds)) // 写入/更新后过期时长
                .build();
    }
}
